package com.daydayup.homework;

import java.util.LinkedList;
import java.util.List;

public class A {
	/**
	 * 
	 * 5=3*0+2*0+1*5, 5=3*0+2*1+1*3, 5=3*0+2*2+1*1, 5=3*1+2*0+1*2, 5=3*1+2*1+1*0
	 */
	private static final int[] DATA = { 3, 2, 1 };
	private static final int SUM = 5;
	private static String s = "";

	public static void main(String[] args) {
		List<LinkedList<Integer>> arr = new LinkedList<LinkedList<Integer>>();
		for (int i = 0; i < DATA.length; i++) {
			LinkedList<Integer> ll = new LinkedList<Integer>();
			for (int j = 0; j <= SUM; j++) {
				if (DATA[i] * j <= SUM) {
					ll.add(j, DATA[i] * j);
				}
			}
			arr.add(i, ll);
		}

		test(arr, SUM);

		System.out.println(arr);
	}

	static void test(List<LinkedList<Integer>> arr, int count) {
		for (int i = 0; i < arr.size(); i++) {
			LinkedList<Integer> a = arr.get(i);
			if (a.contains(count)) {
				System.out.println("------------------------------------");
				System.out.println(a.size() + " i =  " + i + " count = " + count);
				// int index = i+DATA.length-arr.size();
				System.out.println(SUM + " = " + s + count);
				count = SUM;
				s = "";
				break;
			} else {
				for (int j = 0; j < a.size(); j++) {
					if (count >= a.get(j)) {
						count = count - a.get(j);
						if (a.get(j) != 0) {
							// s += DATA[index] +" * " + a.get(j)/DATA[index] +
							// "+";
							s += a.get(j) + "+";
						}

					} else {
						s = "";
						break;
					}
					List<LinkedList<Integer>> arr2 = new LinkedList<LinkedList<Integer>>();
					arr2.addAll(arr);
					arr2.remove(i);
					test(arr2, count);
				}
			}
		}
	};
}
